<?php
	require("header.php");
?>
<?php
	//如果不是qc提示无法访问此网页
	if($userType === "admin" or !isset($_GET["id"])) {
		header("location: accesserror.php");
	}
	//查询数据
	$connect = mysql_connect("localhost","root","yxs147789");
	if ($connect) {
	  	mysql_select_db("inspectdb", $connect);
	  	mysql_query("set names 'utf8'");
	   	$problemResult = mysql_query("SELECT * FROM problems WHERE id=".$_GET["id"]);
	   	while($problem = mysql_fetch_array($problemResult)) {
	   		$id = $problem["id"];
	   		$project = $problem["project"];
	   		$city = $problem["city"];
	   		$startTime = $problem["start_time"];
	   		$storeNum = $problem["store_num"];
	   		$storeName = $problem["store_name"];
	   		$storeAddress = $problem["store_address"];
	   		$questionNum = $problem["question_num"];
	   		$state = $problem["state"];
	   		$endTime = $problem["end_time"];
	   }
	}
	mysql_close($connect);
?>
<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> <span><i class="icon-home"></i> 问题单管理</span></div>
  </div>

  <div class="container-fluid">
    <div class="row-fluid">
      <div class="widget-box">
        <div class="widget-title bg_lg"><span class="icon"><i class="icon-th-list"></i></span>
          <h5>问题单详情</h5>
        </div>
        <div class="widget-content nopadding">
            <form class="form-horizontal">
              <?php
	              if(!isset($id)) { 
	              	echo '<div class="alert alert-error">';
	              	echo '<strong>查找失败!</strong>没找到编号为'.$_GET["id"].'的问题单</div>';
	              }
              ?>
              <div class="center control-group">
                <label class="control-label">问卷单编号 :</label>
                <label class="control-label"><strong><?=isset($id)?$id:""?></strong></label>
              </div> 
              <div class="center control-group">
                <label class="control-label">项目 :</label>
                <label class="control-label"><strong><?=isset($project)?$project:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">城市 :</label>
                <label class="control-label"><strong><?=isset($city)?$city:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">执行日期 :</label>
                 <label class="control-label"><strong><?=isset($startTime)?$startTime:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺编号 :</label>
                <label class="control-label"><strong><?=isset($storeNum)?$storeNum:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺名 :</label>
                <label class="control-label"><strong><?=isset($storeName)?$storeName:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">店铺地址 :</label>
                <label class="control-label"><strong><?=isset($storeAddress)?$storeAddress:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">问卷题目号码 :</label>
                <label class="control-label"><strong><?=isset($questionNum)?$questionNum:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">问题单状态 :</label>
                <label class="control-label"><strong><?=isset($state)?$state:""?></strong></label>
              </div>
              <div class="center control-group">
                <label class="control-label">结束时间 :</label>
                <label class="control-label"><strong><?=isset($endTime)?$endTime:""?></strong></label>
              </div>
            </form>
          </div>
      </div>
    </div>
  </div>
  
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="widget-box">
        <div class="widget-title bg_lg"><span class="icon"><i class="icon-th-list"></i></span>
          <h5>项目人员反馈</h5>
        </div>
        <div class="widget-content nopadding">
            <?php
            	//把反馈意见查询出来
	            $connect = mysql_connect("localhost","root","yxs147789");
				if ($connect) {
				  	mysql_select_db("inspectdb", $connect);
				  	mysql_query("set names 'utf8'");
	              	$userResult = mysql_query("SELECT * FROM problem_info WHERE problem_id='".$id."'");
				    while($user = mysql_fetch_array($userResult)) {
				   		echo $user["user_name"]."<br>";
				   		if(isset($user["user_idea"])) {
				   			$ideas = explode(",",$user["user_idea"]);
				   			foreach($ideas as $index=>$idea) { 
				   				echo ($index+1).".".$idea."<br>";
				   			}
				   		} else {
				   			echo "暂无反馈<br>";
				   		}
				   }
				}
				mysql_close($connect);
            ?>
            <form class="form-horizontal">
              
            </form>
          </div>
      </div>
    </div>
  </div>

  <div class="container-fluid">
    <div class="row-fluid">
      <div class="widget-box">
        <div class="widget-title bg_lg"><span class="icon"><i class="icon-th-list"></i></span>
          <h5>操作</h5>
        </div>
        <div class="widget-content nopadding">
            <form id="ideaForm" class="form-horizontal" method="post" action="doaddidea.php">
              <?php
              	if(isset($_GET["result"])) { 
              		$result = $_GET["result"];
              		echo '<br>';
              		if($result !== "success") { 
              			echo '<div class="alert alert-error">';
              			echo '<strong>提交失败!</strong> ' . $result . '</div>';
              		} else { 
              			echo '<div class="alert alert-success">';
              			echo '<strong>提交成功!</strong>已成功更新</div>';
              		}
              	}
              ?>
              <input type="hidden" name="id" value="<?=$id?>"/>
              <input id="closePost" type="hidden" name="close" value="false"/>
              <textarea name="idea" class="form-control span12" placeholder="请在这里输入..." rows="3"></textarea>
              <br><br>
              <div class="control-group text-center">
              	<?php
              		if($userType === "supervisor") { 
              			echo '<input type="submit" value="提交意见" class="btn btn-large btn-success"/>';
              			echo '<label id="closeProblem" class="btn btn-large btn-danger">关闭问题单</label>';
              		} else if($userType === "qc") { 
              			echo '<input type="submit" value="提交意见" class="btn btn-large btn-success"/>';
              		} else { 
              			echo '<input type="submit" value="提交执行反馈" class="btn btn-large btn-success"/>';
              		}
              	?>
              </div>
              <br>
            </form>
          </div>
      </div>
    </div>
  </div>
<?php
	require("footer.php");
?>
<script>
	$(document).ready(function() { 
		$("#closeProblem").click(function() { 
			$("#closePost").attr("value", "true");
			$("#ideaForm").submit();
		});
	});
</script>
